/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.loveprog.bean;

import br.com.loveprog.core.services.CoreService;
import br.com.loveprog.core.services.CoreServiceFactory;
import br.com.loveprog.modelo.Usuario;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;

/**
 *
 * @author Leandro
 */
@ManagedBean
@RequestScoped
public class UsuarioMB {

    private static final CoreService CORE = CoreServiceFactory.create();
    private String login;
    private String senha;
    private Usuario usuario;
    CoreService getInstanceCoreService() {
        return CORE;
    }

    public String logarSistema() {
        FacesContext context = FacesContext.getCurrentInstance();
        final CoreService core = this.getInstanceCoreService();

        Usuario result = core.validaUsuario(this.login, this.senha);
        if (result != null) {
            context.addMessage("", new FacesMessage(FacesMessage.SEVERITY_ERROR, "Erro ao Cadastrar", null));
            return "fracasso";
        }else{
            return "sucesso";
        }
    }

    /**
     * @return the login
     */
    public String getLogin() {
        return login;
    }

    /**
     * @param login the login to set
     */
    public void setLogin(String login) {
        this.login = login;
    }

    /**
     * @return the senha
     */
    public String getSenha() {
        return senha;
    }

    /**
     * @param senha the senha to set
     */
    public void setSenha(String senha) {
        this.senha = senha;
    }

    /**
     * @return the usuario
     */
    public Usuario getUsuario() {
        return usuario;
    }

    /**
     * @param usuario the usuario to set
     */
    public void setUsuario(Usuario usuario) {
        this.usuario = usuario;
    }
}
